package com.tang.deliver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tang.common.entity.deliver.Deliver;
import com.tang.deliver.mapper.DeliverMapper;
import com.tang.deliver.service.DeliverService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 唐朝阳
 * @since 2022-05-21
 */
@Service
public class DeliverServiceImpl extends ServiceImpl<DeliverMapper, Deliver> implements DeliverService {

    @Autowired
    private DeliverMapper deliverMapper;

    @Override
    public PageInfo<Deliver> listDeliver(String keywords, Integer currentPage, Integer pageSize, String companyName,Integer state) {
            PageHelper.startPage(currentPage,pageSize);
            if (keywords == null || "".equals(keywords)) {
                QueryWrapper<Deliver> qw = new QueryWrapper<Deliver>();
                qw.eq("delete_flag",1);
               qw.eq("state",state);
                qw.eq("company_name",companyName);
                return PageInfo.of(deliverMapper.selectList(qw));
            }
            QueryWrapper<Deliver> queryWrapper = new QueryWrapper<Deliver>();
            queryWrapper.eq("delete_flag",1).eq("state",state).eq("company_name",companyName).and(q->q.like("user_name",keywords).or().like("job_name",keywords));
            List<Deliver> deliver = deliverMapper.selectList(queryWrapper);
            return  PageInfo.of(deliver);

    }
}
